<?php


namespace app\controller;


use app\model\User;
use think\facade\Session;
use think\facade\View;

class Login
{
    public function toLogin(){
        // 模板输出
        return View::fetch('index');
    }

    public function login(){
        $user = request()->post();
        $result= User::where('email',$user['email'])->where('password',$user['password']) ->find();
        if ($result!=null){
            Session::set('id', $result['id']);
            Session::set('username', $result['username']);
            return redirect('/');
        }else{
            View::assign('msg',"用户名/密码错误");
            return View::fetch('index');
        }
    }

    public function outLogin(){
        Session::clear();
        return View::fetch('index');
    }

}